package com.atguigu.spzx.cloud.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.atguigu.spzx.cloud.user.entity.User;
import com.atguigu.spzx.cloud.user.service.UserService;
import com.atguigu.spzx.cloud.user.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userServer;
    @Autowired
    private UserServiceImpl userServiceImpl;

    @SentinelResource("hot")  // 声明资源名称
    @GetMapping(value = "/findUserByUserId/{userId}")
    public User findUserByUserId(@PathVariable Long userId, @RequestHeader String Truth){
        System.out.println("Truth = " + Truth);
        return userServer.findUserByUserId(userId);
    }


    // 修改用户数据端点
    @GetMapping(value = "/updateUserById")
    public String updateUserById() {
        return "修改用户数据成功";
    }


    @GetMapping(value = "/save")
    public String save() {
        userServiceImpl.queryUsers();
        System.out.println("保存用户");
        return "订单保存成功" ;
    }

    @GetMapping(value = "/query")
    public String query() {
        userServiceImpl.queryUsers();
        System.out.println("查询用户");
        return "查询用户成功" ;
    }
}
